<?php
require('../cofd/functions.php');
$realip =  x_real_ip();
require('../cofd/common.php');
require_once('../setting.php');
$url = $_SERVER['REQUEST_URI'];
if (preg_match('/\?(.*)/', $url, $matches)) {
    $getids = $matches[1];
} else {
    die('没有查询字符串');
}
$stmt = $conn->prepare("SELECT exmattm,exmatanse,exmatother,exmatfrom FROM exam_page WHERE linkshare = ?");
if ($stmt === false) {
    echo json_encode(array('status' => 500, 'msg' => '准备查询失败: ' . $mysqli->error));
    exit();
}
function check_loginok(){
    global $api_authcode_human;
    session_start(); 
    if (isset($_SESSION['authorized_s']) && $_SESSION['authorized_s'] === true && time() < $_SESSION['expires_at_s']) {
    } else {   
        session_write_close();
        die('<p style="color: blue; text-decoration: underline; cursor: pointer;" onclick="window.location.href=\'../student/\';">请先登录!同时需要绑定老师</p>');
    } 
    session_start();
    if($api_authcode_human['api_authcode_human_open'] == 'open'){
        if(!$_SESSION['exam_smrz_s']){
            die('<p style="color: blue; text-decoration: underline; cursor: pointer;" onclick="window.location.href=\'../student/\';">请先完成实名认证</p>');
        }
    }
    session_write_close();
}
$stmt->bind_param('s', $getids); 
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $list_result = $row;
    }
} else {
    die('没有查询到数据');
}
function fixArray($array) {
    $result = array();
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $result[$key] = fixArray($value);
        } else {
            if (is_string($value) && ctype_digit($value)) {
                $result[$key] = intval($value);
            } else {
                $result[$key] = $value;
            }
        }
    }
    return $result;
}
function array_fromtext($input) {
    return json_decode($input, true);
}
$myid = '0';
function ifintheteachbind($teachid){
    global $conn;
    global $myid;
    $myid = $_COOKIE['exam_userid_s'];
    $stmt = $conn->prepare("SELECT bindteacher FROM exam_student WHERE id = ?");
    $stmt->bind_param('s', $myid); 
    $stmt->execute();
    $result = $stmt->get_result();
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            $bindteach = $row['bindteacher'];
        }
    }
    if($bindteach == '' || $bindteach == null){
        die('<p style="color: blue; text-decoration: underline; cursor: pointer;" onclick="window.location.href=\'../student/\';">请先绑定老师</p>');
    }
    $bindteach_array = explode(',', $bindteach);
    if(in_array($teachid, $bindteach_array)){
        return true;
    }else{
        die('<p style="color: blue; text-decoration: underline; cursor: pointer;" onclick="window.location.href=\'../student/\';">请先绑定老师</p>');
    }
}
$newarrays_n = array_fromtext($list_result['exmatother']);
if($newarrays_n[4] == 1){
    check_loginok();
    ifintheteachbind($list_result['exmatfrom']);
}
$stmt->close();
$conn->close();
$file_path = '../ast/justs/done.js';
$file_path2 = '../ast/justs/getfunc.json';
$file_content = file_get_contents($file_path);
$file_content2 = file_get_contents($file_path2);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loading</title>
    <link rel="stylesheet" href="/ast/justs/ok.css">
    <link rel='stylesheet' href='/ast/message/message.min.css'>
    <script src='/ast/message/message.min.js'></script>
    <link rel="stylesheet" href="/ast/layui/css/layui.css">
    <script src='/ast/yhload/load.js'></script>
    <script src="/ast/layui/layui.js"></script>
    </head>
  
<body gotmans_ip=<?php echo $realip; ?> id="scribodymain">
<div class="gotmainshowdex">数据加载中</div>
<div class="godindextomain"> 诚信考试，禁止作弊！<br>绘图题绘图完毕后双击提交</div>
</body>
<div id="autocomplete-list" class="autocomplete-items"></div>
<div id="main_wait_sid" class="main_wait">

</div>
<div id="main_end">
    <button id="button_end_exma" style="width: 100%;display:none" class="layui-btn layui-btn-primary layui-border-blue" onclick="end_ok_exam_end_jj(1);">提交试卷</button>
</div>
</html>
<script src="/plugin/lz-string/libs/lz-string.min.js"></script>
<script src='/ast/yhload/load.js'></script>
<script src="/ast/exam.js"></script>
<script id="scriptincontent">
    document.getElementById('scriptincontent').remove();
    function gettwoexam_ok_doneinmyhand() {
        var exam_page_exmatm = <?php echo json_encode($list_result['exmattm']); ?>;
        var exam_page_exmatanse = <?php echo json_encode($list_result['exmatanse']); ?>;
        var exam_page_loginedid = <?php echo json_encode($myid); ?>;
        return {
            exam_page_exmatm: exam_page_exmatm,
            exam_page_exmatanse: exam_page_exmatanse,
            exam_page_loginedid:exam_page_loginedid
        };
    }
    function eval_json_ans_codetipsall(){
        var json_ans = <?php echo json_encode($file_content2); ?>;
        return json_ans;
    }
    var dynamicJS = <?php echo json_encode($file_content); ?>;
    eval(dynamicJS);
</script>